package cn.itcast.health.admin.controller;

import cn.itcast.health.admin.logs.OperationLog;
import cn.itcast.health.commons.entity.Result;
import cn.itcast.health.commons.resources.MessageConstant;
import cn.itcast.health.commons.utils.LogUtils;
import cn.itcast.health.interfaces.service.ReportService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/report")
public class ReportController {
    @Reference
    private ReportService reportService;

    @RequestMapping("/getMemberReport.do")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.QUERY, operationContent = "会员折线图所需要的数据")
    public Result getMemberReport(){

        try{
            Map map =  reportService.getMemberReport();
            return  new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }
    }
    @RequestMapping("/getGenderReport.do")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.QUERY, operationContent = "饼图会员男女占比所需要数据")
    public Result getGenderReport(){

        try{
            List<Map> map =  reportService.getGenderReport();
            System.out.println(map);
            return  new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }
    }
    @RequestMapping("/getBirthdayReport.do")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.QUERY, operationContent = "饼图会员年龄占比所需要数据")
    public Result getBirthdayReport(){

        try{
            List<Map> map =  reportService.getBirthdayReport();
            return  new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }
    }
}
